<%@ page import="com.fhd.constant.Constants" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.fhd.pojo.Merchant" %>
<%@ page import="com.mysql.cj.util.StringUtils" %><%--
  Created by IntelliJ IDEA.
  User: 44252
  Date: 2025/3/28
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>我要订房</title>
</head>
<body>
<%--回到客户主页--%>
<a href="<%=request.getContextPath()%>/jsp/clientFrame.jsp">返回</a>
<br><br><br><br>
<%--模糊查询--%>
<span>请输入您要搜索的店铺名:</span>
<form method="post" action="<%=request.getContextPath()%>/client.do">
    <%--告知业务层要干什么--%>
    <input type="hidden" name="method" value="selectShopName">
    <label>
        <input type="text" name="shopName" required >
    </label>
    <input type="submit" value="搜索">
</form>
<br>
<span>排序：</span>
<form action="<%=request.getContextPath()%>/client.do" method="post">
    <%--  告知Servlet要做什么  --%>
    <input type="hidden" name="method" value="orderMerchant">
    <label for="soldNumberOrder">按销量排：</label>
    <select name="soldNumberOrder" id="soldNumberOrder">
        <option value="null">无</option>
        <option value="ASC">升序</option>
        <option value="DESC">降序</option>
    </select>
    &nbsp;&nbsp;&nbsp;
    <label for="createDateOrder">按发布时间排：</label>
    <select name="createDateOrder" id="createDateOrder">
        <option value="null">无</option>
        <option value="ASC">升序</option>
        <option value="DESC">降序</option>
    </select>
    &nbsp;&nbsp;
    <input type="submit" value="排序">
</form>
<%
    String object = (String) request.getSession().getAttribute(Constants.ORDER_MESSAGE);
    if (object != null) {
        out.write("<span style=\"color: red\">" + object + "</span>");
        request.getSession().removeAttribute(Constants.ORDER_MESSAGE);
    }

    //得到下单返回信息
    String object1 = (String)request.getSession().getAttribute(Constants.CLIENT_PLACE_ORDER_MESSAGE);
    if (!StringUtils.isNullOrEmpty(object1)) {
        out.print("<h2 style=\"color: red\">" + object1 + "</h2>");
        request.getSession().removeAttribute(Constants.CLIENT_PLACE_ORDER_MESSAGE);
    }
%>
<br>
<span>以下是所有店铺:</span>
<br><br>
<%
    String object2 = (String) request.getSession().getAttribute(Constants.GET_MERCHANT_MESSAGE);
    if (object2 != null) {
        out.write("<h4 style=\"color: red\">" + object2 + "</h4>");
        request.getSession().removeAttribute(Constants.GET_MERCHANT_MESSAGE);
    } else {
        ArrayList<Merchant> merchants = (ArrayList<Merchant>) request.getSession().getAttribute(Constants.GET_MERCHANT_SESSION);
        if (merchants != null && !merchants.isEmpty()) {
            // 判断是否有用户展示
            boolean flag = false;
            for (Merchant merchant : merchants) {
                // 只有通过申请的商家能被客户看到
                if (merchant.getApplySituation() == 1) {
                    flag = true;
                    out.print("店铺名："+merchant.getShopName()+"<br>");
                    out.print("店铺关键词："+merchant.getKeyWord()+"<br>");
                    out.print("联系电话："+merchant.getPhone()+"<br>");
                    out.print("销量："+merchant.getSoldNumber()+"<br>");
                    out.print("创建日期："+merchant.getCreateDate()+"<br>");
                    int openSituation = merchant.getOpenSituation();
                    if (openSituation == 0) {
                    out.print("营业状态：未营业"+"<br>");
                    } else {
                    out.print("营业状态：已营业"+"<br>");
                    }
%>
<br>
<form action="<%=request.getContextPath()%>/client.do" method="post">
    <input type="hidden" name="method" value="getMerchantInformationAndHouse">
    <input type="hidden" name="merchantId" value="<%=merchant.getId()%>">
    <input type="submit" value="进入店铺">
</form>
<%
                    out.print("===============================<br>");
                }
            }
            if (!flag) {
                // 没有商家能被看到
                out.print("暂且没有商家通过审核呢，请耐心等待<br>");
            }
        }
    }
%>
<br>

</body>
</html>